﻿using System;
using WeiboSharp.Web;

namespace WeiboSharp
{
    public partial class WeiboClient
    {
        public void ExecuteAsync(WeiboRequest request, Action<WeiboResponse> callback)
        {
            request = AuthenticateIfNeeded(request);

            IHttp http = new Http();
            http = ConfigureHttp(request, http);

            switch (request.Method)
            {
                case WebMethod.Get:
                    http.GetAsync(r => ProcessResponse(r, callback));
                    break;
                case WebMethod.Post:
                    http.PostAsync(r => ProcessResponse(r, callback));
                    break;
                case WebMethod.Put:
                    http.PutAsync(r => ProcessResponse(r, callback));
                    break;
                case WebMethod.Delete:
                    http.DeleteAsync(r => ProcessResponse(r, callback));
                    break;
                case WebMethod.Head:
                    http.HeadAsync(r => ProcessResponse(r, callback));
                    break;
                case WebMethod.Options:
                    http.OptionsAsync(r => ProcessResponse(r, callback));
                    break;
            }
        }

        void ProcessResponse(WeiboResponse restResponse, Action<WeiboResponse> callback)
        {
            callback(restResponse);
        }
    }
}
